package com.xinqi.modules.course.textbook.controller.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.course.textbook.dto.req.CourseCloudTextbookContentCreateDTO;
import com.xinqi.modules.course.textbook.dto.req.CourseCloudTextbookContentQueryDTO;
import com.xinqi.modules.course.textbook.dto.req.CourseCloudTextbookContentUpdateDTO;
import com.xinqi.modules.course.textbook.dto.rsp.CourseCloudTextbookContentResultDTO;
import com.xinqi.modules.course.textbook.service.CourseCloudTextbookContentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * 课程模块云课本课堂内容APP控制层
 *
 * @author: wenjie
 * @date: 2023/05/30
 */
@Tag(name = "App-课程模块云课本课堂内容", description = "课程模块云课本课堂内容App接口")
@RestController
@RequestMapping("/app/course-cloud-textbook-content")
@RequiredArgsConstructor
public class CourseCloudTextbookContentAppController {
    private final CourseCloudTextbookContentService courseCloudTextbookContentService;

    /**
     * 课程模块云课本课堂内容-分页
     */
    @Operation(summary = "课程模块云课本课堂内容-分页")
    @GetMapping("/page")
    public R<PageInfo<CourseCloudTextbookContentResultDTO>> page(@ParameterObject CourseCloudTextbookContentQueryDTO dto) {
        PageInfo<CourseCloudTextbookContentResultDTO> page = courseCloudTextbookContentService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 课程模块云课本课堂内容-详情
     */
    @Operation(summary = "课程模块云课本课堂内容-详情")
    @GetMapping("/{id}")
    public R<CourseCloudTextbookContentResultDTO> findById(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        CourseCloudTextbookContentResultDTO dto = courseCloudTextbookContentService.findById(id);
        return R.data(dto);
    }

    /**
     * 新增课程模块云课本课堂内容
     */
    @Operation(summary = "新增课程模块云课本课堂内容")
    @PostMapping
    public R<Long> insert(@RequestBody CourseCloudTextbookContentCreateDTO dto) {
        return R.data(courseCloudTextbookContentService.insert(dto));
    }

    /**
     * 修改课程模块云课本课堂内容
     */
    @Operation(summary = "修改课程模块云课本课堂内容")
    @PutMapping("/{id}")
    public R<Boolean> update(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id,
                             @RequestBody CourseCloudTextbookContentUpdateDTO dto) {
        dto.setId(id);
        return R.data(courseCloudTextbookContentService.updateById(dto));
    }

    /**
     * 删除课程模块云课本课堂内容
     */
    @Operation(summary = "删除课程模块云课本课堂内容")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        return R.data(courseCloudTextbookContentService.deleteById(id));
    }
}
